<template>
  <div class="i_bg">  
        <div class="content mar_20">
            <img src="../../../assets/images/img3.jpg" />        
        </div>
        <div class="warning">        	
            <table border="0" style="width:1000px; text-align:center;" cellspacing="0" cellpadding="0">
              <tr height="35">
                <td style="font-size:18px;">
                	感谢您在本店购物！您的订单已提交成功，请记住您的订单号: <font color="#ff4e00">{{ outTradeNo }}</font>
                </td>
              </tr>
              <tr>
                <td style="font-size:14px; font-family:'宋体'; padding:10px 0 20px 0; border-bottom:1px solid #b6b6b6;">
                	您选定的配送方式为: <font color="#ff4e00">申通快递</font>； &nbsp; &nbsp;您选定的支付方式为: <font color="#ff4e00">{{ payway == 1 ? '微信支付':'支付宝支付' }}</font>； &nbsp; &nbsp;您的应付款金额为: <font color="#ff4e00">￥{{totalPrice}}</font>
                </td>
              </tr>
              <!-- <tr>
                <td style="padding:20px 0 30px 0; font-family:'宋体';">
                	支付宝网站(www.alipay.com) 是国内先进的网上支付平台。<br />
                    支付宝收款接口：在线即可开通，零预付，免年费，单笔阶梯费率，无流量限制。<br />
                    <a href="#" style="color:#ff4e00;">立即在线申请</a>
                </td>
              </tr> -->
              <tr>
                <td>
                	<div class="btn_u" style="margin:0 auto; padding:0 20px; width:120px;"><a @click.once="pay">立即使用{{ payway == 1 ? '微信支付':'支付宝支付' }}</a></div>
                	<router-link to="/front-index">首页</router-link> &nbsp; &nbsp; <a href="#">用户中心</a>
                </td>
              </tr>
            </table>        	
        </div>
    </div>

</template>

<script>
export default {
    name:'CartThree',
    mounted(){
        this.outTradeNo = this.$route.query.outTradeNo;
        this.payway = this.$route.query.payway;
        this.totalPrice = this.$route.query.totalPrice;
    },
    data:function(){
       return{
            outTradeNo:'',
            payway:-1,
            totalPrice:''
       }
    },
    methods:{


        //支付宝支付
        alipay(){
            this.$axios({
                    method:'get',
                    url:'/easybuy/zf',
                    params:{serialNumber:this.outTradeNo}
                }).then(rs=>{
                    var mydiv = document.createElement('div');
                    mydiv.innerHTML=rs.data;
                    // 查找表单并验证
                    const form = mydiv.querySelector('form');
                    if (!form) {
                        throw new Error('支付表单未正确生成');
                    }
                    // 动态插入并提交
                    document.body.appendChild(mydiv);
                    form.submit(); // 直接使用找到的表单元素
                })
        },
      wxpay(){

        this.$axios({
                method:'post',
                url:'/easybuy/wxzf',
                data:{
                    outTradeNo:this.outTradeNo
                }
            }).then(rs=>{
                this.$router.push({path:'/show-code',query:{url:rs.data.pay_url,'outTradeNo':this.outTradeNo}});
            })
      },
        pay(){
            this.$axios({
                url:'/easybuy/order/getone',
                params:{
                    outTradeNo:this.outTradeNo
                }
            }).then(rs=>{
                if(rs.data.ispay == 2){
                    this.$message.error('订单已超时！');
                    this.$router.replace('/goodslist');
                }else{
                    if(this.payway == 1){
                      this.wxpay();
                    }else{
                      this.alipay();
                    }
                }
            })
            
        }
    }
}
</script>

<style>

</style>